package middle;

import java.util.Scanner;

/**
 * MT12 网格走法数目
 * @author d3y1
 */
public class MT12{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution1(in);
            solution2(in);
        }
    }

    /**
     * 递归
     *
     * f(i, j) = f(i-1, j)+f(i, j-1)
     *
     * @param in
     */
    private static void solution1(Scanner in){
        int row = in.nextInt();
        int col = in.nextInt();

        System.out.println(f(row, col));
    }

    private static int f(int i, int j){
        if(i==0 || j==0){
            return 1;
        }

        return f(i-1, j)+f(i, j-1);
    }

    /**
     * 动态规划
     *
     * dp[i][j]表示小团从左上角起点(0,0)到当前点(i,j)的走法数目
     * dp[i][j] = dp[i-1][j]+dp[i][j-1]
     *
     * @param in
     */
    private static void solution2(Scanner in){
        int row = in.nextInt();
        int col = in.nextInt();

        int[][] dp = new int[row+1][col+1];
        for(int i=0; i<=row; i++){
            dp[i][0] = 1;
        }
        for(int j=0; j<=col; j++){
            dp[0][j] = 1;
        }

        for(int i=1; i<=row; i++){
            for(int j=1; j<=col; j++){
                dp[i][j] = dp[i-1][j]+dp[i][j-1];
            }
        }

        System.out.println(dp[row][col]);
    }
}